#RGB图像大律法二值化使用例程，rgb的把大律法放在while主循环里会出现白图片
import sensor, image, time,machine
from pyb import LED

sensor.reset()
sensor.set_vflip(False)
sensor.set_hmirror(False)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.
#sensor.set_windowing([0,20,80,40])
sensor.skip_frames(time = 2000)     # WARNING: If you use QQVGA it may take seconds
clock = time.clock()                # to process a frame sometimes.


LED(1).on()
LED(2).on()
LED(3).on()

for i in range(60):
    img = sensor.snapshot()
    histogram = img.get_histogram()
    Thresholds = histogram.get_threshold()
    l = Thresholds.l_value()
    a = Thresholds.a_value()
    b = Thresholds.b_value()
    print(Thresholds)

while(True):
    clock.tick()
    img = sensor.snapshot()
    img.binary([(0, l), (-128, a),(-128, b)])
